%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Edited by Shu Jiang, 2011.
% ALL RIGHTS ARE RESERVED.
% mailto: shujiang@tamu.edu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot the configuration variables
% human angles 
% robotic model angles
% time scaled to 1
% double column
function meanValuePlot_robotConfig(ave_time,x_mean,name,...
    ylabelstr,q,ns_time,outputIndex)

figure;
hold on
apc3 = 0.775000000000000*0.7;
apc4 = 0.690000000000000*0.7;
apc = [0.100000000000000   0.2000000000000   apc3   apc4];
% error band
E= std(x_mean)*ones(size(ave_time));
pp1 = errorbar(ave_time(1:4:end),x_mean(1:4:end),E(1:4:end),'ro');
hold on;


% plot the robot configuration variables
pp2 = plot(ns_time,q,'k');


xlim([0 1]);

set(pp1,'MarkerSize', 10,'LineWidth',2);
set(pp2,'MarkerSize', 10,'LineWidth',3);
set(gca,'position',apc);

xlabel({'Scaled Time'},'Interpreter','LaTex','FontSize',20)
ylabel({ylabelstr},'Interpreter','LaTex','FontSize',20)

set(gca,'FontSize',16)


% legend
switch outputIndex
    case 1
    l=legend({'$p^H_{hip} \pm \sigma$','$p_{hip}^{R}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 2
        l=legend({'$p^{L,H}_{hip} \pm \sigma$','$p_{hip}^{L,R}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 3
        l=legend({'$m^{H}_{nsl} \pm \sigma$','$m_{nsl}^{R}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 4
        l=legend({'$m^{L,H}_{nsl} \pm \sigma$','$m_{nsl}^{L,R}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 5
        l=legend({'$\theta^{H}_{hip} \pm \sigma$','$\theta_{hip}^{R}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 6
        l=legend({'$\theta^{H}_{sk} \pm \sigma$','$\theta_{sk}^{R}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 7
        l=legend({'$\theta^{H}_{nsk} \pm \sigma$','$\theta_{nsk}^{R}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 8
        l=legend({'$\theta^{H}_{sf} \pm \sigma$','$\theta_{sf}^{R}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
end
p = get(l,'position');
set(l, 'position', [0 p(2)-.2 1-0.2 p(4)], 'Box','off');
nameFolder = strcat('fig/',name);
print(gcf, '-depsc',nameFolder)


end
